package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"im/global"
	"im/models"
)

type DanmuController struct {
	beego.Controller
}

func (d *DanmuController) DanmuAdd() {
	Mode, _ := d.GetInt("mode")
	Text := d.GetString("text")
	Stime, _ := d.GetInt("stime")
	Size, _ := d.GetInt("size")
	Color := d.GetString("color")
	Area := d.GetString("area")

	if Mode == 0 {
		Mode = 1
	}

	if Stime == 0 {
		Stime = 1000
	}

	if Size == 0 {
		Size = 25
	}

	if Color == "" {
		Color = "0xffffff"
	}

	if Area == "" {
		Area = "content"
	}

	dannmu := models.Dannmu{
		Mode:  Mode,
		Text:  Text,
		Stime: Stime,
		Size:  Size,
		Color: Color,
		Area:  Area,
	}

	global.Db.Table("danmu").Create(&dannmu)

	d.Data["json"] = global.Response{
		Code:    0,
		Message: "弹幕新增OK",
		Data:    nil,
	}

	d.ServeJSON()
}
